package com.zz.cc.owner.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;

import com.zz.cc.owner.R;
import com.zz.cc.owner.TitleBaseActivity;

public class LoginActivity extends TitleBaseActivity
	implements OnClickListener, OnCheckedChangeListener
	{
	
	private EditText mUserNameInput;
	private EditText mPasswordInput;
	
	private Button mLoginBtn;
	private Button mRegisterBtn;
	
	private TextView mForgetPasswordInput;
	
	private CheckBox mManualCheckBox;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		initUI();
		fillView();
	}
	
	private void initUI() {
		mUserNameInput = (EditText) findViewById(R.id.login_input_user_name);
		mPasswordInput = (EditText) findViewById(R.id.login_input_password);
		mLoginBtn = (Button) findViewById(R.id.login_login);
		mRegisterBtn = (Button) findViewById(R.id.login_register);
		mForgetPasswordInput = (TextView) findViewById(R.id.login_forget_password);
		mManualCheckBox = (CheckBox) findViewById(R.id.login_manual);
	}
	
	private void fillView() {
		super.setCurrentTitle(R.string.login_title);
		mLoginBtn.setOnClickListener(this);
		mRegisterBtn.setOnClickListener(this);
		mForgetPasswordInput.setOnClickListener(this);
		mManualCheckBox.setOnCheckedChangeListener(this);
		mManualCheckBox.setOnClickListener(this);
	}
	
	private void gotoForgetPasswordActivity() {
		Intent intent = new Intent(this, ForgetPasswordActivity.class);
		startActivity(intent);
		overridePendingTransition(R.anim.activity_slide_right_in, R.anim.activity_slide_left_out);
	}
	
	private void gotoMainActivity() {
		Intent intent = new Intent(this, NewMainActivity.class);
		startActivity(intent);
		finish();
		overridePendingTransition(R.anim.activity_slide_right_in, R.anim.activity_slide_left_out);
	}
	
	private void gotoRegisterActivity() {
		Intent intent = new Intent(this, RegisterPhoneNumActivity.class);
		startActivity(intent);
		overridePendingTransition(R.anim.activity_slide_right_in, R.anim.activity_slide_left_out);
	}

	@Override
	public void onClick(View view) {
		int id = view.getId();
		switch(id) {
		case R.id.login_login:
			//TODO
			gotoMainActivity();
			break;
			
		case R.id.login_register:
			gotoRegisterActivity();
			break;
			
		case R.id.login_forget_password:
			gotoForgetPasswordActivity();
			break;
			
		default:
			break;
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		
	}
}
